package com.kk.fatory;

import java.io.IOException;
import java.util.*;

public class PersonFactory {
    static Properties p;
    static Map<String,String> keyValueMap;
    static {
        keyValueMap =new HashMap();
        p = new Properties();
        try {
            p.load(PersonFactory.class.getClassLoader().getResourceAsStream("person.properties"));
            Enumeration<?> enumeration = p.propertyNames();
            while (enumeration.hasMoreElements()) {
                Object o = enumeration.nextElement();
                String s = o + "";
                Object value = p.getProperty(s);
                keyValueMap.put(s, (String) value);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static Object getBean(String name) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        String o = keyValueMap.get(name);
        return Class.forName(o).newInstance();
    }
}
